package com.wisemoresystem.seal.util;

import java.io.File;
import java.net.URL;
import java.util.Enumeration;
import java.util.HashSet;
import java.util.Set;

import org.ne.framework.data.util.MysqlOrmTools;

public class SqlCreateTools {

	public static Set<Class> getObjectsInPackage(String packName) {
		Set<Class> objs = new HashSet<Class>();
		String packageName = packName;
		String packageDirName = packageName.replace(".", "/");
		Enumeration<URL> dirs = null;
		try {
			dirs = Thread.currentThread().getContextClassLoader()
					.getResources(packageDirName);
			// 迭代此 Enumeration
			while (dirs.hasMoreElements()) {
				URL url = dirs.nextElement();
				File file = new File(url.getFile());
				// 把此目录下的所有文件列出
				String[] classes = file.list();
				// 循环此数组，并把.class去掉
				for (String className : classes) {
					className = className.substring(0, className.length() - 6);
					// 拼接上包名，变成全限定名
					String qName = packageName + "." + className;

					objs.add(Class.forName(qName));
				}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		return objs;
	}

	public static void main(String[] args) {

		// clazz);
		Set<Class> clazzs = getObjectsInPackage("com.uninf.b2b.model");
		for (Class clazz : clazzs) {
			String createSql = MysqlOrmTools.getCreateSql(clazz);
			System.err.println(createSql);
		}

	}
}
